package com.gxar.quick.ar.server.base.common.enums.protocol;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 协议编辑器枚举
 *
 * @author zxh
 * @version 1.0
 * @created 2024/01/02.
 */
@Getter
public enum ArProtocolEditorEnum {

    WEB_EDITOR("web", "Web编辑器"),

    UNITY_EDITOR("unity", "Unity编辑器"),

    ;

    private final String name;
    private final String desc;

    ArProtocolEditorEnum(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static ArProtocolEditorEnum getByName(String name) {
        return getByNameOrDefault(name, null);
    }

    public static ArProtocolEditorEnum getByNameOrDefault(String name, ArProtocolEditorEnum defaultEnum) {
        Optional<ArProtocolEditorEnum> targetEnum = Arrays.stream(ArProtocolEditorEnum.values()).filter(e -> e.getName().equals(name)).findFirst();
        return targetEnum.orElse(defaultEnum);
    }
}
